﻿using Fetion.Model;
using ProtoBuf;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Fetion.Core
{
    public delegate void ResponseHandle(object result);

    public class Request<T>:IMessage
    {
        
        private PackageModel model;

        public PackageModel Model
        {
            get { return model; }
            set { model = value; }
        }
        public EventHandler<ClientAsyncCompletedEventArgs<T>> CompleteHandle { get; set; }

        public ResponseHandle ResHandle;
        
        public Request(PackageModel m)
        {
            model = m;
        }

        //public Request(int userId,int cmd,byte[] body)
        //{
        //    model.UserId=
        //    _userId = userId;
        //    _cmd = cmd;
        //    _body = body;

        //}
        //public void SetBody<T>(int userid, T model)
        //{
        //    _userId = userid;
        //    Type t = typeof(T);
        //    _cmd = ReqCmdDic.GetCMD(t.Name);
        //    using (MemoryStream bodyMs = new MemoryStream())
        //    {
        //        Serializer.Serialize<T>(bodyMs, model);
        //        _body = bodyMs.GetBuffer();
        //    }
        //}
        //public Request(int userId, T model)
        //{
        //    _userId = userId;
        //    Type t = typeof(T);
        //    _cmd = ReqCmdDic.GetCMD(t.Name);
        //    using (MemoryStream bodyMs = new MemoryStream())
        //    {
        //        Serializer.Serialize<T>(bodyMs, model);
        //        _body = bodyMs.GetBuffer();
        //    }
        //}
        //public  void Init<T>(int userId, int cmd, byte[] body, T model)
        //{
        //    _userId = userId;
        //    _cmd = cmd;
        //    Type t = typeof(T);
        //    using (MemoryStream bodyMs = new MemoryStream())
        //    {
        //        Serializer.Serialize<T>(bodyMs, model);
        //        _body = bodyMs.GetBuffer();
        //    }
        //}



        public void Save(BufferWriter writer)
        {
            throw new NotImplementedException();
        }

        public void Load(BufferReader reader)
        {
            throw new NotImplementedException();
        }


        public byte[] GetBuffer()
        {
            return model.GetBuffer();
        }
    }
}
